﻿<script>
    var _sorts = [{ id: 0, title: "请选择退款原因" },
        { id: 1, title: "多拍" },
        { id: 2, title: "质量问题" },
        { id: 3, title: "发错货" },
        { id: 4, title: "不想要了" },
        { id: 5, title: "协商退货" },
        { id: 6, title: "其他" }
    ];

    var _sts = [{ id: 0, title: "待审核" },
    { id: 1, title: "同意退款" },
    { id: 2, title: "取消退款" }
    ];
    var _file_domain = "@ViewBag.FileDomain";
    var uploader;

    
 



    var _vm;
    $(function () {
        var vm = new PageViewModel();
        _vm = vm;
        ko.applyBindings(vm);
        vm.init();

    });
 

    function PageViewModel()
    {
        var me = this;
        ViewModel.call(me);
        vmExtend.call(me);

        me.url = "/Wiki/Refund/Models";
        me.deleteUrl = "/Wiki/Refund/Delete";

        
        me.dialog = new FormDialog(me);
         
    }
    function vmExtend() {
        var me = this;
    }


    function FormDialog(vm) {
        var me = this;
        Dialog.call(me);

        me.onOpen = function () {

            if (!uploader) {
                uploader = WebUploader.create({
                    auto: true,
                    swf: '/Content/webuploader/Uploader.swf',
                    server: '/Wiki/Product/FileSave',
                    pick: '#picker',
                    resize: false
                });

                uploader.on('uploadSuccess', function (file, response) {
                    //$('#' + file.id).find('.progress').fadeOut();
                     

                    if (response.st == "1")
                    {
                        $("#RefundFile").val(response.msg);
                        $("#thelist").append("<img class='img_thum img_red' src='" + _file_domain + response.msg + "' />");
                    }
                    else
                    {
                        $ace.alert(response.msg);
                    }


                });
            }

            var model = me.editModel();
            if (model) {
                var bindModel = $ko.toJS(model);
                me.model(bindModel);
                
                
                //console.log(bindModel);
                
                $("#RefundFile").val(bindModel.RefundFile);

                $("#thelist").empty();
                if (bindModel.RefundFile != "")
                {
                     
                    var s1 = $("#RefundFile").val();
                    if (s1 != "")
                    {
                        $("#thelist").append("<img class='img_thum img_red' src='" + _file_domain + s1 + "' />");
                    }
 
                }
            }
            else
            {
                 
                $("#RefundFile").val("");
                $("#thelist").empty();   
            }
        }

        me.onSave = function () {
            if (!$('#form1').formValid()) {
                return false;
            }

            var model = me.model();

            if (me.editModel()) {
                
                $ace.post("/Wiki/Refund/Edit", model, function (result) {
                    $ace.msg(result.Msg);
                    me.close();
                    vm.dataTable.reload();
                    //setTimeout(function () { window.location.reload(); }, 1000);
                }
                );
            }
            else {
                model.RefundFile = $("#RefundFile").val(); 
                $ace.post("/Wiki/Refund/Add", model, function (result) {
                    $ace.msg(result.Msg);
                    me.close();
                    vm.loadData();
                    //setTimeout(function () { window.location.reload(); }, 1000);
                }
                );
            }
        }
    }

</script>
